<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Bulletin</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Le styles -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="css/bootstrap-responsive.css" rel="stylesheet">
    <link href="js/bootstrap.js" rel="stylesheet">
    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
</head>
<body>

<?php
$status_array = array("1"=>"已发布","0"=>"待发布");

include("/usr/local/apache2/htdocs/jibaiwang/lib/Bulletin.php");
include("/usr/local/apache2/htdocs/jibaiwang/lib/Notifaction.php");
include('log4php/Logger.php');
$cfgfile = "/usr/local/apache2/htdocs/jibaiwang/admin/bootstrap/conf/config.ini";
$defarray = parse_ini_file($cfgfile, 1);
$qlogtag = $defarray["Bulletin"]['qlogtag'];
Logger::configure($defarray["Bulletin"]['qlogcfg']);
$logger = Logger::getLogger($qlogtag);
$host = $defarray["Bulletin"]["host"];
$user = $defarray["Bulletin"]["user"];
$pass = $defarray["Bulletin"]["pass"];
$db = $defarray["Bulletin"]["db"];
$dbh = new Sqlexecutor($host, $user, $pass, $db);
$s = new Bulletin($dbh,$logger);
$p = new Notifaction($dbh,$logger);
if($_REQUEST["submit"] == 1)
{
    $res = $s->create($_REQUEST["Bulletin_buffer"]);
}
if($_REQUEST["op"] == "del")
{
    $res = $s->deleteByID($_REQUEST["rule_id"]);
}    
if($_REQUEST["op"] == "on")
{
    $res = $s->publishByID($_REQUEST["rule_id"]);
    $res = $p->push('');
}
$list = $s->getList();
//var_dump($list);
?>
<legend>历史公告记录    <a data-toggle="modal" href="#myModal" class="btn btn-warning btn-large">添加新公告</a></legend>
    <div class="span20">
      <table class="table table-striped">
        <thead>
          <tr>
            <th>#</th>
            <th>公告内容</th>
            <th>状态</th>
            <th>添加时间</th>
            <th>上次发布时间</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
        <form class="well form-inline" target="_self">
<?php
    foreach($list as $key => $value)
    {
        echo "<tr>";
        echo '<td><input id="b_'.$value["id"].'" type="hidden" class="span1" name="b_id" readonly value="'.$value["id"].'">'.$value["id"].'</td>';
        echo '<td><textarea readonly id="content_'.$value["id"].'" name="content" class="span6" rows="5">'.$value["content"].'</textarea></td>';
        echo "<td>".$status_array[$value["status"]]."</td>";
        echo "<td>".$value["insert_date"]."</td>";
        echo "<td>".$value["publish_date"]."</td>";
//        echo '<td><button value="2" type="submit" name="submit" class="btn-mini" onclick="modify_del('.$value["id"].')" >发布</button><button value="3" type="submit" name="submit" class="btn-mini" >修改</button></td>';
        echo "<td>";
//        echo '<div class="btn-group"><a  class="btn btn-small btn-info dropdown-toggle" data-toggle="dropdown" href="#"><span class="caret"></span></a>';
        echo '<div class="btn-group"><button  class="btn btn-warning dropdown-toggle" data-toggle="dropdown" href="#">操作<span class="caret"></span></button>';
        echo '<ul class="dropdown-menu">'; 
        echo '<li><a onclick="modify_on('.$value["id"].')"><i class="icon-ok"></i> 发布</a></li>';
        echo '<li><a onclick="modify_del('.$value["id"].')"><i class="icon-trash"></i> 删除</a></li>';
        echo "</div>";
        echo "</td>";
        echo "</tr>";
    }
?>
        </form>
        </tbody>
      </table>
    </div>
    <div id="myModal" class="modal hide fade">
<div class="modal-header">
    <a class="close" data-dismiss="modal" >&times;</a>
    <h3>新建公告</h3>
    </div>

<form class="form-horizontal" target="_self">
    <div class="control-group">
        <label class="control-label" for="textarea">请输入公告信息</label>
        <div class="controls">
            <textarea class="input-xlarge" name="Bulletin_buffer" id="textarea" rows="3"></textarea>
        </div>
    </div> 
           <button value="1" type="submit" name="submit" class="btn btn-warning btn-large" style="right:500px margin-top:10px; margin-left:50px; margin-left:10px; margin-bottom:10px;">提交</button>
</form>
</div>


    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster
    <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> -->
    <script src="js/jquery.js"></script>
    <script src="js/google-code-prettify/prettify.js"></script>
    <script src="js/bootstrap-transition.js"></script>
    <script src="js/bootstrap-alert.js"></script>
    <script src="js/bootstrap-modal.js"></script>
    <script src="js/bootstrap-dropdown.js"></script>
    <script src="js/bootstrap-scrollspy.js"></script>
    <script src="js/bootstrap-tab.js"></script>
    <script src="js/bootstrap-tooltip.js"></script>
    <script src="js/bootstrap-popover.js"></script>
    <script src="js/bootstrap-button.js"></script>
    <script src="js/bootstrap-collapse.js"></script>
    <script src="js/bootstrap-carousel.js"></script>
    <script src="js/bootstrap-typeahead.js"></script>
    <script src="js/application.js"></script>
    <script src="js/customize.js"></script>
    
<script type="text/javascript">
function modify_del(id){
        if(window.confirm("确定删除吗？")){
            str="?op=del&rule_id="+id
            window.open(str,'_self');
        }
}

function modify_on(id){
    if(window.confirm("确定发布吗？")){
        str="?op=on&rule_id="+id
            window.open(str,'_self');
    }
}
</script>
    
<script>
$('.carousel').carousel({
    interval: 12000
})
</script>

</body>
</html>
